home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Freeware / Miro 1.0 / Miro_Installer.exe / xulrunner / python / frontend_implementation / VideoDisplay.py < prev   
Encoding:
Python Source  |  2007-11-12  |  6.4 KB  |  179 lines

  1. # Miro - an RSS based video player application
  2. # Copyright (C) 2005-2007 Participatory Culture Foundation
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  17.  
  18. import app
  19. import frontend
  20. import os
  21. import util
  22. import config
  23. import prefs
  24. from download_utils import nextFreeFilename
  25.  
  26. from xpcom import components
  27. from threading import Lock
  28. import frontend
  29. import time
  30.  
  31. selectItemLock = Lock()
  32.  
  33. ###############################################################################
  34. #### The Playback Controller                                               ####
  35. ###############################################################################
  36.  
  37. class PlaybackController (app.PlaybackControllerBase):
  38.     
  39.     def playItemExternally(self, itemID):
  40.         item = app.PlaybackControllerBase.playItemExternally(self, itemID)
  41.         # now play this item externally
  42.         moviePath = ""
  43.         try:
  44.             moviePath = os.path.normpath(item.getVideoFilename())
  45.             os.startfile(moviePath)
  46.         except:
  47.             print "DTV: movie %s could not be externally opened" % moviePath
  48.  
  49. ###############################################################################
  50. #### Right-hand pane video display                                         ####
  51. ###############################################################################
  52.  
  53. class VideoDisplay (app.VideoDisplayBase):
  54.     "Video player shown in a MainFrame's right-hand pane."
  55.  
  56.     def initRenderers(self):
  57.         self.renderers.append(VLCRenderer())
  58.  
  59.     def setArea(self, area):
  60.         # we hardcode the videodisplay's area to be mainDisplayVideo
  61.         pass
  62.     def removedFromArea(self):
  63.         # don't care about this either
  64.         pass
  65.  
  66.     def goFullScreen(self):
  67.         return frontend.vlcRenderer.goFullscreen(url)
  68.  
  69.     def exitFullScreen(self):
  70.         return frontend.vlcRenderer.exitFullScreen(url)
  71.  
  72.     def setVolume(self, volume, moveSlider=True): 
  73.         app.VideoDisplayBase.setVolume(self, volume)
  74.         frontend.vlcRenderer.setVolume(self.volume)
  75.         if moveSlider:
  76.             frontend.jsBridge.positionVolumeSlider(self.volume)
  77.  
  78.     def fillMovieData (self, filename, movie_data, callback):
  79.         print "fillMovieData (%s)" % (filename,)
  80. #        dir = os.path.join (config.get(prefs.ICON_CACHE_DIRECTORY), "extracted")
  81. #        try:
  82. #            os.makedirs(dir)
  83. #        except:
  84. #            pass
  85. #        screenshot = os.path.join (dir, os.path.basename(filename) + ".png")
  86.  
  87. #        movie_data["screenshot"] = nextFreeFilename(screenshot)
  88.         movie_data["screenshot"] = u""
  89.  
  90.         self.movie_data = movie_data
  91.         self.callback = callback
  92.  
  93. #       Uncomment this to enable duration extraction
  94.  
  95. #         print "Calling renderer"
  96.         frontend.vlcRenderer.extractMovieData (filename, movie_data["screenshot"]);
  97. #         print "renderer returned"
  98.  
  99.     def extractFinish (self, duration, screenshot_success):
  100.         print "extractFinish (%d, %s)" % (duration, screenshot_success)
  101.         self.movie_data["duration"] = int (duration)
  102.         if screenshot_success:
  103.             self.movie_data["screenshot"] = u""
  104. #            if self.movie_data["screenshot"] and not os.path.exists(self.movie_data["screenshot"]):
  105. #                self.movie_data["screenshot"] = u""
  106.         else:
  107.             self.movie_data["screenshot"] = None
  108.         self.callback()
  109.  
  110. # This is a major hack to avoid VLC crashes by giving it time to
  111. # process each stop or play command. --NN
  112. def lockAndPlay(func):
  113.     def locked(*args, **kwargs):
  114.         global selectItemLock
  115.         selectItemLock.acquire()
  116.         try:
  117.             ret = func(*args, **kwargs)
  118.             time.sleep(1)
  119.             return ret
  120.         finally:
  121.             selectItemLock.release()
  122.     return locked
  123.  
  124. class VLCRenderer (app.VideoRenderer):
  125.     """The VLC renderer is very thin wrapper around the xine-renderer xpcom
  126.     component. 
  127.     """
  128.  
  129.     def canPlayFile(self, filename):
  130.         url = util.absolutePathToFileURL(filename)
  131.         return frontend.vlcRenderer.canPlayURL(url)
  132.  
  133.     @lockAndPlay
  134.     def selectFile(self, filename):
  135.         url = util.absolutePathToFileURL(filename)
  136.         return frontend.vlcRenderer.selectURL(url)
  137.     def setVolume(self, volume): 
  138.         return frontend.vlcRenderer.setVolume(volume)
  139.     @lockAndPlay
  140.     def reset(self): 
  141.         return frontend.vlcRenderer.reset()
  142.     @lockAndPlay
  143.     def play(self): 
  144.         return frontend.vlcRenderer.play()
  145.     def pause(self): 
  146.         return frontend.vlcRenderer.pause()
  147.     @lockAndPlay
  148.     def stop(self): 
  149.         return frontend.vlcRenderer.stop()
  150.     def goToBeginningOfMovie(self): 
  151.         return frontend.vlcRenderer.goToBeginningOfMovie()
  152.     def getDuration(self): 
  153.         return frontend.vlcRenderer.getDuration()
  154.     def getCurrentTime(self): 
  155.         try:
  156.             return frontend.vlcRenderer.getCurrentTime()
  157.         except:
  158.             return None
  159.     def setCurrentTime(self, time): 
  160.         return frontend.vlcRenderer.setCurrentTime(time)
  161.     @lockAndPlay
  162.     def playFromTime(self, time): 
  163.         return frontend.vlcRenderer.playFromTime(time)
  164.     def getRate(self): 
  165.         return frontend.vlcRenderer.getRate()
  166.     def setRate(self, rate): 
  167.         return frontend.vlcRenderer.setRate(rate)
  168.  
  169.     def movieDataProgramInfo(self, videoPath, thumbnailPath):
  170.         # We don't use the app name here, so custom
  171.         # named versions can use the same code --NN
  172.         moviedata_util_filename = "Miro_MovieData.exe"
  173.         cmdLine = [moviedata_util_filename, videoPath, thumbnailPath]
  174.         return cmdLine, None
  175.  
  176.  
  177. ###############################################################################
  178. ###############################################################################
  179.